using System; 

namespace EstimationStudio.Core
{
	/// <summary>
	///  The <see cref="ErrorVariability"/> class represents the variable range of error for a particular estimate.
	/// </summary>
	[Serializable]
	public class ErrorVariability
	{
        /// <summary>
        /// Initializes a new instance of the <see cref="ErrorVariability"/> class.
        /// </summary>
        public ErrorVariability()
        {
        }

		/// <summary>
		/// Initializes a new instance of the <see cref="ErrorVariability"/> class.
		/// </summary>
		/// <param name="low">The low value of the <see cref="Estimate"/>.</param>
		/// <param name="high">The high value of the <see cref="Estimate"/>.</param>
        public ErrorVariability(Double low, Double high)
        {
            Low = low;
            High = high;
        }
        
		/// <summary>
		///  Gets or Sets the low variability value of the <see cref="Estimate"/>.
		/// </summary>
        public Double Low { get; set; }

		/// <summary>
		///  Gets or Sets the high variability value of the <see cref="Estimate"/>.
		/// </summary>
        public Double High { get; set; }

		/// <summary>
		///  Gets the calculated range of the low and high variability value for the <see cref="Estimate"/>.
		/// </summary>
		public Double Range
		{
			get { return Math.Round((1 / Low) * High, 2); }
		}

		/// <summary>
		/// Multiplies a <see cref="ErrorVariability"/> with the specified factor.
		/// </summary>
		/// <param name="errorVariability">The <see cref="ErrorVariability"/> to multiply.</param>
		/// <param name="factor">The factor to multiply with.</param>
		/// <returns></returns>
		public static ErrorVariability operator * (ErrorVariability errorVariability, Double factor)
		{
			return new ErrorVariability(errorVariability.Low * factor, errorVariability.High * factor);
		}

        public override string ToString()
        {
            return String.Format("{0} - {1}", Low, High);
        }
	}
}